package com.usian;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext-redis.xml")
public class ZSet {
    @Autowired
    private RedisTemplate redisTemplate;
    //存值
    @Test
    public void set(){
        redisTemplate.boundZSetOps("zhu").add("a",156);
        redisTemplate.boundZSetOps("zhu").add("b",154);
        redisTemplate.boundZSetOps("zhu").add("c",146);
    }
    //查询  从低到高
    @Test
    public void qGet(){
        Object zhu = redisTemplate.boundZSetOps("zhu").range(0,-1);
        System.out.println(zhu);
    }
    //从高到低
    @Test
    public void gGet(){
        Object zhu = redisTemplate.boundZSetOps("zhu").reverseRange(0,9);
        System.out.println(zhu);
    }
    //修改  添加分数
    @Test
    public void update(){
        redisTemplate.boundZSetOps("zhu").incrementScore("a",2055);
    }
    //查值 分数
//    @Test
//    public void getTest(){
//        Object zhu = redisTemplate.boundZSetOps("zhu").reverseRangeWithScores(0,-1);
//
//    }

}
